// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'//引入高德地图
import VueAwesomeSwiper from 'vue-awesome-swiper'
import App from './App'
import router from './router'
import store from '@/store/index.js'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import { ToastPlugin,LoadingPlugin, ConfirmPlugin, AlertPlugin } from 'vux'
// import fastClick from 'fastclick'
import './assets/styles/iconfont.css'
import 'swiper/dist/css/swiper.css'
import './assets/styles/aui.css'
import './assets/styles/mobile.css'
import AMap from 'AMap'
import { getRegionByAdcode } from '@/api/allapis'
import Lockr from 'Lockr'


Vue.config.productionTip = false
// fastClick.attach(document.body)
Vue.use(VueAwesomeSwiper)
Vue.use(ToastPlugin, {position: 'middle', 'is-show-mask': true, time: 1500}) // toast默认参数值
Vue.use(LoadingPlugin) // 加载中插件 this.$vux.loading.show({ text: 'Loading' });  this.$vux.loading.hide()
Vue.use(ConfirmPlugin)
Vue.use(AlertPlugin)
// console.log(router)
router.beforeEach((to,from,next)=>{
	var Mytoken = Lockr.get('Admin-Token')	
	if (to.matched.some(record => record.meta.login)){  // 判断该路由是否需要登录权限
			// console.log('1')
    if(Mytoken){
    	// alert(1)
      	next()
    }else{
    	next('/login');
    }
  }else {
    next();
  }
})
/* eslint-disable no-new */

// Lockr.set('myRegion', {id: 1333, parent_id: 188, name: "洛阳市市辖区", level: 3, adcode: "410301", company_id: 1})

// AMap.plugin('AMap.Geolocation', function() {
//     var geolocation = new AMap.Geolocation({
//         enableHighAccuracy: true,//是否使用高精度定位，默认:true
//         timeout: 10000,          //超过10秒后停止定位，默认：5s
//         buttonPosition:'RB',    //定位按钮的停靠位置
//         buttonOffset: new AMap.Pixel(10, 20),//定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
//         zoomToAccuracy: true,   //定位成功后是否自动调整地图视野到定位点

//     });
//      // alert(this_.Adcode)
//     // map.addControl(geolocation);
//     // console.log('start locationing')
//     geolocation.getCurrentPosition(function(status,result){
//         if(status=='complete'){
//             // onComplete(result)
            
//             // this_.Adcode = result.addressComponent.adcode
//             // console.log(result)
//             getRegion(result.addressComponent.adcode)
//             // this_.getCompanyId()//换取company_id

//         }else{
//             // onError(result)
//         }
//     });
// });
// async function getRegion(adcode) {
// 	let res = await getRegionByAdcode(adcode)
// 	// Lockr.set('myRegion', res.data.region_info)
// }
new Vue({
  el: '#app',
  router,
  store,
  components: { App },
  template: '<App/>'
})
